import request from '@/utils/request'
import { PatientResponseData, PatientByIdResponseData, Patient } from './type'

enum API {
  GET_PATIENT_URL = '/user/patient/auth/findAll',
  DELETE_PATIENT_URL = '/user/patient/auth/remove/',
  GET_PATIENT_INFO_URL = '/user/patient/auth/get/',
  SAVE_PATIENT_INFO_URL = '/user/patient/auth/save',
  // 更新就诊人
  UPDATE_PATIENT_INFO_URL = '/user/patient/auth/update'
}

export const reqPatientList = () => request.get<any, PatientResponseData>(`${API.GET_PATIENT_URL}`)

// 删除就诊人
export const reqDeletePatient = (id: number) => request.delete(`${API.DELETE_PATIENT_URL}${id}`)

// 获取就诊人信息
export const reqPatientInfoById = (id: string) =>
  request.get<any, PatientByIdResponseData>(`${API.GET_PATIENT_INFO_URL}${id}`)

// 新增就诊人
const reqSavePatientInfo = (data: Patient) =>
  request.post<any, any>(`${API.SAVE_PATIENT_INFO_URL}`, data)

// 更新就诊人
const reqUpdatePatientInfo = (data: Patient) =>
  request.put<any, any>(`${API.UPDATE_PATIENT_INFO_URL}`, data)

// 更新或修改就诊人
export const reqUpdateOrSavePatientInfo = (data: Patient) =>
  data.id ? reqUpdatePatientInfo(data) : reqSavePatientInfo(data)
